package numUniqueEmails;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public int numUniqueEmails(String[] emails) {
        Set<String> set = new HashSet<>();
        for (String email: emails) {
            StringBuilder sb = new StringBuilder();
            // 先拼接本地名
            int i = 0;
            for (; i < email.length(); i++) {
                char c = email.charAt(i);
                if(c == '@'){
                    break;
                }else if(c == '+'){
                    break;
                }else if(c!='.'){
                    sb.append(c);
                }
            }
            // 再拼接域名
            // 找到域名的@字符所在索引开始拼接
            for (;i<email.length();i++){
                if(email.charAt(i) == '@'){
                    break;
                }
            }
            i++;
            for (;i<email.length();i++){
                sb.append(email.charAt(i));
            }
            set.add(sb.toString());
        }
        return set.size();
    }
}
